package com.atguigu.eduservice.controller;


import com.atguigu.commonutils.R;
import com.atguigu.eduservice.entity.EduComment;
import com.atguigu.eduservice.service.EduCommentService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 评论 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2020-07-31
 */
@RestController
@RequestMapping("/eduservice/edu-comment")
public class EduCommentController {
    @Autowired
    private EduCommentService eduCommentService;
    //分页查询评论内容
    @GetMapping("/pageComment/{current}/{limit}")
    public R pageListComment(@PathVariable long current,@PathVariable long limit){
        Page<EduComment> commentPage = new Page<>(current,limit);
        eduCommentService.page(commentPage,null);
        long total = commentPage.getTotal();//总记录数
        List<EduComment> records = commentPage.getRecords();//数据list集
        return R.ok().data("total",total).data("rows",records);
    }
    //添加评论
    @PostMapping("/addComment")
    public R addComment(@RequestBody EduComment eduComment){
        boolean save =  eduCommentService.save(eduComment);
        if (save){
            return R.ok();
        }else {
            return R.error();
        }
    }

}

